
class TestStatic {
    public static int staticNum = 100;
    public int data1 = 10;

    {
        //构造代码块 || 实例代码块
        System.out.println("实例代码块被执行了....");
        data1 = 1000;//一般情况下  用来初始化 非静态的数据成员
        //staticNum = 1000000;
    }

    static {
        //静态代码块
        System.out.println("静态代码块被执行了....");
        staticNum = 9999;
    }

    static {
        staticNum = 91999;
    }

    public TestStatic() {
        System.out.println("执行构造方法.....");
    }

    public static void main5(String[] args) {
        TestStatic testStatic = new TestStatic();
        //System.out.println(testStatic.data1);
        // System.out.println(TestStatic.staticNum);
    }
}
class Student{
    public String name;
    public int age;
    public static String classRoom = "2-201";//静态成员变量

/*    public static String getClassRoom(){
        System.out.println(this);
        return classRoom;
    }//无法从静态上下文引用 非静态变量 this*/

 /*   public static String getClassRoom(){
        age+=1;
        return getClassRoom();
    }//无法从静态上下文引用 非静态变量 age*/
}


public class Test {

    public static void main4(String[] args) {

        System.out.println(Student.classRoom);//通过类名访问
    }
    public  static class Computer{
        private String cpu;
        private String memory;
        public String screen;
        String brand;//default属性
        public Computer(String brand,String cpu,String memory,String screen) {
            this.brand = brand;
            this.cpu = cpu;
            this.memory = memory;
            this.screen = screen;
        }
        public void SurfInternet(){
            System.out.println("上网");
        }
    }
    public static void main3(String[] args) {
        Computer c = new Computer("huawei","i9","16G","13*14");
        System.out.println(c.brand);//default属性 只能在同一包中访问
        System.out.println(c.screen);//public属性 可以任何其他类访问
        //System.out.println(s.cpu);  private属性 只能在Computer类中访问，不能在其他类中访问
    }
    public static class Date2{
        public int year;
        public int month;
        public int day;

        //构造方法：
        //名字与类名相同 没有返回值，设置为void也不行
        //一般情况下使用public修饰
        //在创建对象时由编译器自动调用，并且在对象的生命周期只调用一次
        public Date2(int year,int month,int day){
            this.year = year;
            this.month = month;
            this.day = day;
            System.out.println("Date(int,int,int)方法被调用了...");
        }
        public void printDate(){
            System.out.println(year+"/"+month+"/"+day);
        }
    }
    public static void main2(String[] args) {
        Date2 d = new Date2(2021,6,9);//输出Date(int,int,int)方法被调用了...
        d.printDate();//2021/6/9
    }
    public static class Date {
        public int year;
        public int month;
        public int day;

        public void setDate(int year,int month,int day) {
            //局部变量优先使用
            this.year = year;
            this.month = month;
            this.day = day;
        }
        public void printDate (){
            System.out.println(year+"/"+month+"/"+day);
        }

        public static void main2(String[] args) {
            //构建三个日期类型的对象
            Date d1 = new Date();
//            Date d2 = new Date();
//            Date d3 = new Date();
            //对三个对象设置日期
            d1.setDate(1999,2,1);
//            d2.setDate(2020,1,1);
//            d3.setDate(2023,9,9);
            //打印日期中的内容
            d1.printDate();
//            d2.printDate();
//            d3.printDate();
        }
    }
 static class WashMachine {
        public String brand;//品牌
        public String color;//颜色
        public double price;//价格

        public void washClothes() {
            System.out.println("洗衣功能");
        }

        public void dryClothes() {
            System.out.println("脱水");
        }
    }

    public static void main1(String[] args) {
        WashMachine washMachine1 = new WashMachine();//通过new实例化对象
        washMachine1.brand = "media";
        washMachine1.dryClothes();

        WashMachine washMachine2 = new WashMachine();
        washMachine2.brand = "media";
        washMachine2.dryClothes();
    }

}
